#!/bin/bash

path=$2
echo "target-dir=$path"

exports(){

    export CANGJIE_STDX_PATH=$CANGJIE_STDX_DYNAMIC_PATH

    # pattern可省略，有默认值
    export logger_appender_console=FDemoConsole
    # 如果使用 DEBUG，会有很多信息输出（比如定时任务 每秒都会输出）。视情况修改为 DEBUG
    export logger_appender_FDemoConsole_level=DEBUG

    export logger_appender_FDemoConsole_pattern='[%level-%name]%d{yyyy/MM/dd,HH:mm:ss.SSS}|%m'
    export logger_appender_file=FDemoFile
    export logger_appender_FDemoFile_level=INFO
    export logger_appender_FDemoFile_pattern='[%level-%name]%d{yyyy/MM/dd,HH:mm:ss.SSS}|%m'
    export logger_appender_FDemoFile_path=./log/fdemo.log
    export logger_appender_FDemoFile_rotateDuration=DAY

    export mvc_port=8080 # 这一行可以没有，默认就是8080
    export mvc_overallElapsedSwitch=true
#    export mvc_internalServerErrorMessageKind=BEAN
#    export mvc_internalServerErrorMessage=NameOf500Handler



    export orm_noPool=true # 默认是false，true表示不用连接池

    export orm_useStdPool=false # 默认是true
    export orm_drivers=opengauss
    export orm_databasePoolInitSize=10
    export orm_databasePoolMinSize=10
    export orm_databasePoolMaxSize=10
    export orm_databasePoolCheckOnCreation=true
    export orm_databasePoolCheckOnBorrowing=true
    export orm_databasePoolCheckOnReturning=false
    export orm_databasePoolConnectionLife=86400
    export orm_databasePoolCheckInterval=300 # 默认是300，单位是秒
    export orm_databasePoolCheckSql='select 1'

    #    数据库连接是这里
    export opengauss_orm_connectionUrl="opengauss://fountain:Fountain123@pgm-2ze534c0xh8vatxzwo.pg.rds.aliyuncs.com:5432/fountain?sslmode=disable"


    if [[ "$path" == "" ]]; then
        path='./fdemo'
    fi

    export LD_LIBRARY_PATH=$path/release/boot:$path/release/opengauss:$path/release/examples:$LD_LIBRARY_PATH

    export PATH=/root/.cjpm/bin:/root/.cjpm/libs/fboot:$PATH
}

run(){
    exports

#    fboot run $path --dylibPattern='(boot|user\.util\.auth|\.(controller|service\.impl))'
    fboot run $path --dylibPattern='(boot|examples\.exceptions|\.(controller|service\.impl))'
}

build(){
    export CANGJIE_STDX=$CANGJIE_STDX_DYNAMIC_PATH
    export CANGJIE_STDX_PATH=$CANGJIE_STDX_DYNAMIC_PATH

    fboot build $path
    echo -e '\a'
}

cleanUpdate(){
    fboot cleanUpdate $path
    echo -e '\a'
}



case "$1" in
run)
    run
    ;;
cleanUpdate)
    cleanUpdate $2 $3
    ;;
build)
    build
    ;;
launch)
    launch
    ;;
esac

exit $?
